<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>货位列表</title>
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="container">

    <!--{include file='comm/menu.tpl'}-->


        <div class="comm_crub">
            <span class="now_crub">货位列表</span>
        </div>

        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>
                                        选择仓库：<select class="form-control input-sm" id="storeID" name="storeID">
                                            <option value='-1'>请选择</option>
                                            <!--{foreach from=$store_array item=value}-->
                                                <option value='<!--{$value->storeID}-->'><!--{$value->storeName}--></option>
                                            <!--{/foreach}-->
                                        </select>
                                    </span>
                                    <span>货位号：<input type="text" class="form-control input-sm" name="shelf_name" id="shelf_name" style="width: 130px;"></span>

                                    <span>
                                        <button type="button" class="btn btn-primary btn-sm" onclick="storeShelf.search();">查询</button>&nbsp;&nbsp;
                                        <button type="button" class="btn btn-primary btn-sm" onclick="E.refresh();">重置</button>&nbsp;&nbsp;
                                        <!--{if $EDIT_STORESHELFLIST}-->
                                            <button type="button" class="btn btn-primary btn-sm" onclick="storeShelf.importShelf();">导入货位</button>&nbsp;&nbsp;
                                            <button type="button" class="btn btn-primary btn-sm" onclick="storeShelf.exportShelf();">导出货位</button>
                                        <!--{/if}-->
                                    </span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

            <form name="export_form" id="export_form" method="post" action="/quanliadmin/app/wms/store.pscript?operFlg=9">
                <input type="hidden" name="v1" id="v1" value="">
            </form>

        </div>


</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/wms/storeShelf.ajax?operFlg=7&xjx=none",
        dataType: "json",
        colModel : [
            <!--{if $EDIT_STORESHELFLIST}-->
            {display: "操作", width : 60,align:"center"},
            <!--{/if}-->
            {display: "所在仓库", width : 200,align:"left"},
            {display: "货位号", width : 100,name : "shelfID",sortable : true }
        ],
        <!--{if $EDIT_STORESHELFLIST}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "storeShelf.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "storeShelf.delcheck"},
            {separator: true},
            {name: "货位批量添加", bclass: "add", onpress : "storeShelf.batch"}
        ],
        <!--{/if}-->
        sortname: "shelfID",
        sortorder: "desc",
        usepager: true,
        rp: 20,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    //输入框回车事件
    function getEvent( e ){
        if(e.keyCode == 13 ){
            storeShelf.search();
        }
    }

    var storeShelf = {

        //搜索
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({newrp: 1, params: dt}).flexReload();
        },

        //添加
        add: function() {
            E.open("/quanliadmin/app/wms/store.pscript?operFlg=6", "", {height: 400,width: 800, top: 50, left: 150});
        },

        //编辑
        edit: function(storeID , shelfID) {
            E.open("/quanliadmin/app/wms/store.pscript?operFlg=7&storeID=" + storeID + "&shelfID=" + shelfID, "" , {height: 400,width: 800, top: 50, left: 150});
        },

        //批量添加库位
        batch:function(){
            E.open("/quanliadmin/app/wms/store.pscript?operFlg=8", "" , {height: 400,width: 800, top: 50, left: 150});
        },

        /**
         * 导入
         */
        importShelf : function (){
            E.open("/quanliadmin/app/wms/store.pscript?operFlg=10", "", {height: 400,width: 800, top: 50, left: 150});
        },

        exportShelf:function(){
//            $("#v1").val( storeID );
            $("#v1").val(  );
            document.getElementById('export_form').submit();
        },
        //要删除的数组
        delete_arr : { },

        //删除确认
        delcheck: function(){
            if(E.empty($(".trSelected").length)){
                E.alert('请选择货位进行删除');
                return false;
            }
            delete_arr = { };
            $(".trSelected").each(function (k,v){
                var tmp = $(v).attr('id').replace('row','').split('_');
                delete_arr[k] = tmp;
            });

            //弹出确认层
            E.confirm('对应上架货品信息将丢失，是否删除这 ' + $('.trSelected',flex).length + ' 个货位吗?', "storeShelf.del");
        },

        /**
         * 删除
         */
        del: function() {
            jquery_ajax(9, {store_array : delete_arr} , storeShelf.callback );
        },

        //回调函数
        callback: function( obj ) {

            if( obj.code == 200 ){
                E.alert( obj.message , 2 , 'storeShelf.load');
            }else{
                E.alert(obj.message);
            }

        },

        load: function() {
            $("#flex").flexReload();
        }

    };


    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/wms/storeShelf.ajax?operFlg="+flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                alert('网络不给力，请重新尝试...');
            }
        });
    }

</script>

</body>
</html>